cmake_minimum_required(VERSION 3.10)
project(image_server)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找必要的包
find_package(OpenCV REQUIRED)
find_package(realsense2 REQUIRED)
find_package(ZeroMQ REQUIRED)
find_package(nlohmann_json REQUIRED)

# 如果系统中没有nlohmann_json包，可以使用以下方式下载
if(NOT nlohmann_json_FOUND)
    include(FetchContent)
    FetchContent_Declare(
        nlohmann_json
        URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
    )
    FetchContent_MakeAvailable(nlohmann_json)
endif()

# 添加可执行文件
add_executable(image_server 
    main.cpp 
    image_server.cpp
)

# 包含目录
target_include_directories(image_server PRIVATE 
    ${OpenCV_INCLUDE_DIRS}
    ${realsense2_INCLUDE_DIRS}
    ${ZeroMQ_INCLUDE_DIRS}
)

# 链接库
target_link_libraries(image_server PRIVATE 
    ${OpenCV_LIBS}
    ${realsense2_LIBRARY}
    zmq
    pthread
    nlohmann_json::nlohmann_json
)

# 添加编译选项
target_compile_options(image_server PRIVATE -Wall -Wextra -O3)

# 安装规则
install(TARGETS image_server DESTINATION bin)

# 添加单元测试选项
option(BUILD_TESTS "Build tests" OFF)
if(BUILD_TESTS)
    add_executable(image_server_test 
        test/test_image_server.cpp 
        image_server.cpp
    )
    
    target_include_directories(image_server_test PRIVATE 
        ${OpenCV_INCLUDE_DIRS}
        ${realsense2_INCLUDE_DIRS}
        ${ZeroMQ_INCLUDE_DIRS}
    )
    
    target_link_libraries(image_server_test PRIVATE 
        ${OpenCV_LIBS}
        ${realsense2_LIBRARY}
        zmq
        pthread
        nlohmann_json::nlohmann_json
    )
endif()
